<template>
  <div>
    <!-- 面包屑导航 -->
    <el-header>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>权限管理</el-breadcrumb-item>
        <el-breadcrumb-item>角色列表</el-breadcrumb-item>
      </el-breadcrumb>
    </el-header>
    <!-- 主体部分 -->
    <el-card>
      <!-- 权限表格 -->
      <el-table :data="tableData" border>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="name" label="权限名"></el-table-column>
        <el-table-column prop="path" label="路径"></el-table-column>
        <el-table-column prop="level" label="权限级别">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.level===1">一级权限</el-tag>
            <el-tag v-else-if="scope.row.level===2" type="success">二级权限</el-tag>
            <el-tag v-else type="warning">三级权限</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Rights',
  data() {
    return {
      // 存储rights数据
      tableData: []
    }
  },
  created() {
    this.getTableData('list')
  },
  methods: {
    // 获取rights页面的值，type有list和tree两种模式
    async getTableData(type) {
      let { data: res } = await this.$ajax.get(`rights/${type}/`)
      if (res.status === 'success') {
        this.tableData = res.data
        this.$message.success('获取权限列表成功')
      } else
        this.$message.success('获取权限列表失败')
    }
  }
}
</script>

<style scoped>
.el-header {
  display: flex;
  align-items: center;
}
</style>